package edu.hunan.cxb18.controller;

import edu.hunan.cxb18.mapper.UserMapper;
import edu.hunan.cxb18.pojo.User;
import edu.hunan.cxb18.util.sqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @author AuthorName
 * @create 2020-04-05 15:32
 */
@Controller
public class MybatisController {
    @RequestMapping("/Jsontest")
    public @ResponseBody
    List<User> Jsontest(){
        SqlSession sqlSession = sqlSessionUtil.openSession();
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        List<User> users = new ArrayList<>();
        users.add(userMapper.selectByPrimaryKey(1001));
        users.add(userMapper.selectByPrimaryKey(1002));
        users.add(userMapper.selectByPrimaryKey(1003));
        users.add(userMapper.selectByPrimaryKey(1004));
        return users;
    }
}
